package com.cyy.cn.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtTest1 {

    public static void main(String[] args) {

        /*1
        JwtBuilder builder = Jwts.builder().setId("888")
                .setSubject("小黑").setIssuedAt(new Date())
                .signWith(SignatureAlgorithm.HS256,"chenyuyi");
        System.out.println(builder.compact());*/
        //2解析
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4ODgiLCJzdWIiOiLlsI_pu5EiLCJpYXQiOjE1OTA2MzUzNDJ9.xlxO96lMizj-dmIrvi33GPFxq2Dvb_XQvzZvq0XGxrk";
        Claims claims = Jwts.parser().setSigningKey("chenyuyi").parseClaimsJws(token).getBody();
        System.out.println("id:" + claims.getId());
        System.out.println("issuedat" + claims.getIssuedAt());
        System.out.println("subject:" + claims.getSubject());
    }
}
